package cn.itcast.filter;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authz.AuthorizationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyPermsFilter  extends AuthorizationFilter {
    @Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        Subject subject = getSubject(request, response);  // 主题
        String[] perms = (String[]) mappedValue; // perms["部门管理","删除部门"]

        if (perms != null && perms.length > 0) {
            for (String perm : perms) {
                if(subject.isPermitted(perm)){  //当前登录有其中的一个权限
                    return true;
                }
            }
            return false;
        }
        return true;  // 如果  perms=[] 直接return true  直接放行
    }
}
